home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #2
/
Amiga Plus CD - 1999 - No. 2.iso
/
System-Boost
/
Workbench
/
Archive
/
PP_v1.4
/
Source
/
fragalloc.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-11-08
|
1KB
|
61 lines
/* FragAlloc - "end-to-end fragments" allocation and deallocation functions
**
** These two functions are used by Powerpacker Patcher V1.4. They allocate/
** deallocate a block of memory by splitting it up into consequitive,
** smaller blocks.
**
** This file belongs to the Powerpacker Patcher project.
**
** Copyright 1991, Michael Berg
*/
#include <pragmas.h>
#include <exec/types.h>
UBYTE *fragallocabs(int size,register chsize,UBYTE *where)
{
register UBYTE *memgot;
if (memgot = AllocAbs(size,where))
{
register nchunks;
register i;
int lchunk;
nchunks = size / chsize;
lchunk = size % chsize;
Forbid();
FreeMem(memgot,size);
for (i=0; i<nchunks; i++)
AllocAbs(chsize,memgot + i*chsize);
if (lchunk)
AllocAbs(lchunk,memgot + i*chsize);
Permit();
}
return(memgot);
}
void fragfree(register UBYTE *memgot,int size, register chsize)
{
register nchunks;
int lchunk;
nchunks = size / chsize;
lchunk = size % chsize;
while (nchunks--)
{
FreeMem(memgot,chsize);
memgot += chsize;
}
if (lchunk)
FreeMem(memgot,lchunk);
}